//
//  EditCommentViewController.m
//  XDBaseFrameWork
//
//  Created by wanglong8889@126.com on 14-9-29.
//  Copyright (c) 2014年 XD-XY. All rights reserved.
//

#import "EditCommentViewController.h"

@interface EditCommentViewController ()
{
    float total;
    float shoushi;
    float fuwu;
    float zhuanye;
    UIView * picView;
    DLStarRatingControl *shoushiStars;
    DLStarRatingControl *serveStars;
    DLStarRatingControl *professionalStars;
    NSString * ReviewID;
}
@end

@implementation EditCommentViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.titleLabel.text = @"评论";
    
    picId = [[NSString alloc] init];
    ReviewID = [[NSString alloc] init];
    picId = @"";
    ReviewID = @"";
    [self initEditCommentViews];
    [self getNomalConmmentDatas];
}

-(void)initEditCommentViews{
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightButton setTitle:@"发布" forState:UIControlStateNormal];
    [rightButton setTitleColor:self.titleLabel.textColor forState:UIControlStateNormal];
    [rightButton setFrame:CGRectMake(520/2.0f, 13+aHeight, 60, 25)];
    rightButton.titleLabel.font = [UIFont systemFontOfSize:17.5];
    [rightButton addTarget:self action:@selector(saveComments) forControlEvents:UIControlEventTouchUpInside];
    
    [self.navigationBarView addSubview:rightButton];
    
    float scrollSi;
    scrollSi = 88.0;
    
    if (iPhone5) {
        scrollSi = 0.0;
    }
    
    myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height)];
    
    myScrollView.contentSize = CGSizeMake(320, self.contentView.frame.size.height+20+scrollSi);
    
    myScrollView.backgroundColor = [UIColor clearColor];
    
    myScrollView.delegate = self;
    
    [self.contentView addSubview:myScrollView];
    
    
    bigView = [[UIView alloc] initWithFrame:CGRectMake(15, 15, 290,65*3+90)];
    bigView.backgroundColor = RGBA(240, 240, 240, 1);
    bigView.layer.borderColor = RGBA(225, 214, 205, 1).CGColor;
    bigView.layer.borderWidth = .5;
    bigView.layer.cornerRadius = 3.0;
    
    
    [myScrollView addSubview:bigView];
    
    topView = [[UIView alloc] initWithFrame:CGRectMake(1,1, UI_SCREEN_WIDTH-32, 50)];
    
    topView.backgroundColor = [UIColor whiteColor];
    
    [bigView addSubview:topView];
    
    UILabel *ztLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 80, 30)];
    ztLabel.backgroundColor = [UIColor clearColor];
    
    ztLabel.text = @"总体评价";
    
    [topView addSubview:ztLabel];
    
    
    self.customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(ztLabel.frame.origin.x+ztLabel.frame.size.width+20, 5,20*6, 42) andStars:5 isFractional:NO];
	_customNumberOfStars.backgroundColor = [UIColor clearColor];
    _customNumberOfStars.rating = 5;
    _customNumberOfStars.delegate = self;
	_customNumberOfStars.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    
    
    [topView addSubview:_customNumberOfStars];
    
    totalLabel = [[UILabel alloc] initWithFrame:CGRectMake(10+_customNumberOfStars.frame.size.width+_customNumberOfStars.frame.origin.x+10, 10, 30, 30)];
    
    totalLabel.backgroundColor = [UIColor clearColor];
    
    totalLabel.textColor = RGBA(240, 144, 38, 1.0);
    
    totalLabel.text = @"5分";
    
    total = 5;
    
    [topView addSubview:totalLabel];
    
    [self initThreeViews];
    
    
    
    tfView = [[UITextView alloc] initWithFrame:CGRectMake(bigView.frame.origin.x, bigView.frame.origin.y+bigView.frame.size.height+20, bigView.frame.size.width, 100)];
    
    tfView.layer.borderColor = RGBA(225, 214, 205, 1).CGColor;
    
    tfView.layer.borderWidth = .5;
    
    tfView.layer.cornerRadius = 3.0;
    
    tfView.delegate = self;
    
    tfView.font = [UIFont systemFontOfSize:15.0];
    
    [myScrollView addSubview:tfView];
    
    
    placeholderLB = [[UILabel alloc] initWithFrame:CGRectMake(5,5, 120, 20)];
    
    placeholderLB.backgroundColor = [UIColor clearColor];
    
    placeholderLB.text = @"写下您的感受吧！";
    
    placeholderLB.textColor = [UIColor grayColor];
    
    placeholderLB.font = [UIFont systemFontOfSize:15.0];
    
    [tfView addSubview:placeholderLB];
    
    
    picView = [[UITextView alloc] initWithFrame:CGRectMake(tfView.frame.origin.x-1, tfView.frame.origin.y+tfView.frame.size.height+30, topView.frame.size.width+2, 68)];
    
    picView.backgroundColor = [UIColor clearColor];
    
    
    [myScrollView addSubview:picView];

    
    
    for (int i = 0; i<4; i++) {
        UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(74*i, 0, 68, 68)];
        
        if (i == 0) {
            view.image = [UIImage imageNamed:@"camera_comment"];
        }else{
            view.image = [UIImage imageNamed:@"comment_add"];
        }
        
        view.userInteractionEnabled = YES;
        
        view.tag = 1000+i;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addImage:)];
        
        [view addGestureRecognizer:tap];
        
        [picView addSubview:view];
    }
    
    
    
    
    
    
}


////添加图片

-(void)addImage:(UITapGestureRecognizer *)tap{
    //
    UIActionSheet* sheet1 = [[UIActionSheet alloc] initWithTitle:nil delegate:self
                                               cancelButtonTitle:@"取消"
                                          destructiveButtonTitle:nil
                                               otherButtonTitles:@"相机",@"从相册选择",nil];
    
    
    seleMidView = (UIImageView *)tap.view;
    [sheet1 showInView:[self view]];
}

#pragma  代理方法

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    if(buttonIndex ==0){
        [self choseImageWithTypeCameraTypePhotoLibrary:UIImagePickerControllerSourceTypeCamera];
    }else if(buttonIndex == 1){
        [self choseImageWithTypeCameraTypePhotoLibrary:UIImagePickerControllerSourceTypePhotoLibrary];
    }
}



#pragma mark----------------选择图片

-(void)choseImageWithTypeCameraTypePhotoLibrary:(UIImagePickerControllerSourceType)type{
    UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
    
    imagePicker.delegate =self;
    imagePicker.sourceType = type;
    
    imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    
    imagePicker.allowsEditing =YES;
    [self presentViewController:imagePicker animated:YES completion:^{
        
    }];
}

#pragma mark xuan ze zhao pian de dai li
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
    NSData * imageData = UIImageJPEGRepresentation(image,0.6);
    
    NSString *timeSp = [NSString stringWithFormat:@"%ld.jpg", (long)[[NSDate date] timeIntervalSince1970]];
    
    NSString *customId = [[NSUserDefaults standardUserDefaults] objectForKey:kMY_USER_ID];
    
    NSString * requestUrl = [NSString stringWithFormat:@"http://182.92.172.33/Upx.ashx?PTX=%@&SID=%@",@"ReviewPhoto",customId];
    
//    NSString *requestUrl = [NSString stringWithFormat:@"http://182.92.172.33/PhotoUploader.ashx?X=R&F=%@&V=%@",timeSp,customId];
    
    seleMidView.image = image;
    if (![XDTools NetworkReachable]){
        [XDTools showTips:brokenNetwork toView:self.view];
        
        return;
    }

    
    
    
    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:requestUrl]];
    
    [request setRequestMethod:@"POST"];
    [request setTimeOutSeconds:15];
    
    [request addData:imageData withFileName:timeSp andContentType:@"image/jpeg" forKey:@"img"];

    
    
    __weak ASIFormDataRequest * mrequest = request;
    
    
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];
        NSDictionary *resultDictionary = [XDTools JSonFromString:[mrequest responseString]];
        DDLOG(@"res....%@",resultDictionary);
        if ([[resultDictionary objectForKey:@"Succeed"] intValue]==1) {
            
            if ([resultDictionary objectForKey:@"Result"]!=nil){
                NSString * s = [[resultDictionary[@"Result"] componentsSeparatedByString:@"PID="] lastObject];
                if ([picId isEqualToString:@""]) {

                    picId = [picId stringByAppendingString:s];
        
                }else{
                    picId = [picId stringByAppendingString:[NSString stringWithFormat:@",%@",s]];
                }
            }
            
            [XDTools showTips:@"上传成功！" toView:self.view];
        }else{
            [XDTools showTips:[resultDictionary objectForKey:@"Error"] toView:self.view];
        }
    }];
    [request setFailedBlock:^{
        
        [XDTools hideProgress:self.contentView];
        if (mrequest.error.code == 2) {
            [XDTools showTips:@"网络请求超时" toView:self.view];
        }
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView showText:@"正在上传图片"];
    
    [picker dismissViewControllerAnimated:YES completion:^{
    }];
    
}


///////发布评论

-(void)publishComment{
    if (![XDTools NetworkReachable]){
        [XDTools showTips:brokenNetwork toView:self.view];
        
        return;
    }
    if (self.orderId==nil) {
        self.orderId = @"";
    }
    NSString * textString = [[NSString alloc] init];
    if (IS_NOT_EMPTY(tfView.text)){
        textString = tfView.text;
    }else{
        if (total<2){
            textString = @"差评";
        }else if (total<4){
            textString = @"中评";
        }else{
            textString = @"好评";
        }
    }
    CGFloat tt;
    CGFloat ss;
    CGFloat zy;
    CGFloat gt;
    tt = total<1.0?5.0:total;
    ss = shoushi<1.0?5.0:shoushi;   //守时
    zy = zhuanye<1.0?5.0:zhuanye; //专业
    gt = fuwu<1.0?5.0:fuwu;  //沟通
    NSDictionary *dic = @{@"OrderID": self.orderId,
                          @"Rewavg": [NSString stringWithFormat:@"%.0f",tt],
                          @"SS": [NSString stringWithFormat:@"%.0f",ss],
                          @"ZY": [NSString stringWithFormat:@"%.0f",zy],
                          @"GT": [NSString stringWithFormat:@"%.0f",gt],
                          @"Content":textString,
                          @"PhotoID": picId,
                          @"CustomerID":[[NSUserDefaults standardUserDefaults] valueForKey:kMY_USER_ID],
                          @"ReviewID":ReviewID};
    
    ASIFormDataRequest *request = [XDTools postRequestWithDict:dic API:API_PUBLISHCOMMENT];
    
    [request setRequestMethod:@"POST"];
    [request setTimeOutSeconds:15];
    
    __weak ASIFormDataRequest * mrequest = request;
    
    
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];
        NSDictionary *resultDictionary = [XDTools JSonFromString:[mrequest responseString]];
        DDLOG(@"res.publish.%@",resultDictionary);
        if ([[resultDictionary objectForKey:@"status"] intValue]==1) {
            NSString *msg = [resultDictionary objectForKey:@"msg"];
            if (IS_NOT_EMPTY(msg)) {
                [XDTools showTips:msg toView:self.view];
            }
            [self performSelector:@selector(backPrePage) withObject:nil afterDelay:1.0f];
        }else{
            
            NSString *msg = [resultDictionary objectForKey:@"msg"];
            
            if (IS_NOT_EMPTY(msg)) {
                [XDTools showTips:msg toView:self.view];
            }
            
            
        }
    }];
    [request setFailedBlock:^{
        
        [XDTools hideProgress:self.contentView];
        if (mrequest.error.code == 2) {
            [XDTools showTips:@"网络请求超时" toView:self.view];
        }
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView showText:@"正在发布"];
}

//对图片尺寸进行压缩--
-(UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
{
    // Create a graphics image context
    UIGraphicsBeginImageContext(newSize);
    
    // Tell the old image to draw in this new context, with the desired
    // new size
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    // End the context
    UIGraphicsEndImageContext();
    
    // Return the new image.
    return newImage;
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissViewControllerAnimated:YES completion:^{
        
    }];
}


////////////////////////////

////评论回调
-(void)newRating:(DLStarRatingControl *)control :(float)rating{
    
    NSString *state = [self judgeStateByNum:[NSString stringWithFormat:@"%.0f",rating]];
    if (control.tag == 1001) {
        goodtimeLabel.text = state;
        shoushi = rating;
    }else if (control.tag == 1002){
        serveLabel.text = state;
        fuwu = rating;
    }else if (control.tag == 1003){
        professialLabel.text = state;
        zhuanye = rating;
    }else{
        totalLabel.text = [NSString stringWithFormat:@"%.0f分",rating];
        total = rating;
        
    }
}

#pragma mark UITextView Delegate
-(BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
  
    [UIView animateWithDuration:.3 animations:^{
         myScrollView.contentOffset = CGPointMake(0, 180);
    }];
    if(IS_NOT_EMPTY(textView.text)){
        placeholderLB.hidden = YES;
    }else{
        placeholderLB.hidden = NO;
    }
    return YES;
}
-(void)textViewDidChange:(UITextView *)textView
{
    if(IS_NOT_EMPTY(textView.text)){
        placeholderLB.hidden = YES;
    }else{
        placeholderLB.hidden = NO;
    }
    
   
}



-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
   [tfView resignFirstResponder];
}


////////发布评论
-(void)saveComments{
    
    [tfView resignFirstResponder];
    
    myScrollView.contentOffset = CGPointMake(0, 0);
    
    if (total==0&&shoushi==0&&fuwu==0&&zhuanye==0&&(!IS_NOT_EMPTY(tfView.text))&&(!IS_NOT_EMPTY(picId))){
        [XDTools showTips:@"评论内容不能为空！" toView:self.contentView];
        
        return;
    }
    
    [self publishComment];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

-(void)initThreeViews{
    UIView *shoushiView = [[UIView alloc] initWithFrame:CGRectMake(topView.frame.origin.x, topView.frame.origin.y+topView.frame.size.height+10,topView.frame.size.width, 65)];
    
    [bigView addSubview:shoushiView];
    
    UILabel *shoushiLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 35)];
    shoushiLabel.backgroundColor = [UIColor clearColor];
    
    shoushiLabel.text = @"守时";
    
    [shoushiView addSubview:shoushiLabel];
    
    
    shoushiStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(-25,shoushiLabel.frame.origin.y+shoushiLabel.frame.size.height,25*6,25) andStars:5 isFractional:NO];
    shoushiStars.tag = 1001;
	shoushiStars.backgroundColor = [UIColor clearColor];
    [shoushiStars setStar:[UIImage imageNamed:@"face_btn_nor"] highlightedStar:[UIImage imageNamed:@"face_btn_sel"]];
    shoushiStars.rating = 0;
    shoushi = 0;
    shoushiStars.delegate = self;
    shoushiStars.stSpace = 10.0;
    
	shoushiStars.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    
    
    [shoushiStars layoutSubviews];
    [shoushiView addSubview:shoushiStars];
    
    
    
    goodtimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(bigView.frame.size.width-90, shoushiStars.frame.origin.y, 80, 30)];
    goodtimeLabel.backgroundColor = [UIColor clearColor];
    
    goodtimeLabel.textAlignment = NSTextAlignmentRight;
    
    goodtimeLabel.text = @"";
    
    goodtimeLabel.font = [UIFont systemFontOfSize:15.0];
    
    goodtimeLabel.textColor = RGBA(240, 145, 38, 1.0);
    
    [shoushiView addSubview:goodtimeLabel];
    
    
    /////////没时间封装了 。。。。。。。。。。。。
    
    UIView *fuwuView = [[UIView alloc] initWithFrame:CGRectMake(topView.frame.origin.x, shoushiView.frame.origin.y+shoushiView.frame.size.height+10,topView.frame.size.width, 65)];
    
    [bigView addSubview:fuwuView];
    
    UILabel *fuwuLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 35)];
    fuwuLabel.backgroundColor = [UIColor clearColor];
    
    fuwuLabel.text = @"沟通";
    
    [fuwuView addSubview:fuwuLabel];
    
    
    serveStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(-25,fuwuLabel.frame.origin.y+fuwuLabel.frame.size.height,25*6, 25) andStars:5 isFractional:NO];
    
    [serveStars setStar:[UIImage imageNamed:@"face_btn_nor"] highlightedStar:[UIImage imageNamed:@"face_btn_sel"]];
    serveStars.tag = 1002;
	serveStars.backgroundColor = [UIColor clearColor];
    serveStars.rating = 0;
    fuwu = 0;
    serveStars.delegate = self;
	serveStars.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    
    
    [fuwuView addSubview:serveStars];
    
    
    
    serveLabel = [[UILabel alloc] initWithFrame:CGRectMake(bigView.frame.size.width-90, serveStars.frame.origin.y, 80, 30)];
    serveLabel.backgroundColor = [UIColor clearColor];
    serveLabel.textAlignment = NSTextAlignmentRight;
    
    serveLabel.text = @"";
    
    serveLabel.font = [UIFont systemFontOfSize:15.0];
    
    serveLabel.textColor = RGBA(240, 145, 38, 1.0);
    
    [fuwuView addSubview:serveLabel];
    
    
    
    //////////////太2  了?  ..谁太2了？？

    
    UIView *zhuanyeView = [[UIView alloc] initWithFrame:CGRectMake(topView.frame.origin.x, fuwuView.frame.origin.y+fuwuView.frame.size.height+10,topView.frame.size.width, 65)];
    
    [bigView addSubview:zhuanyeView];
    
    UILabel *zhuanyeLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 80, 35)];
    zhuanyeLabel.backgroundColor = [UIColor clearColor];
    
    zhuanyeLabel.text = @"专业";
    
    [zhuanyeView addSubview:zhuanyeLabel];
    
    
    professionalStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(-25,zhuanyeLabel.frame.origin.y+zhuanyeLabel.frame.size.height,25*6, 25) andStars:5 isFractional:NO];
    
    [professionalStars setStar:[UIImage imageNamed:@"face_btn_nor"] highlightedStar:[UIImage imageNamed:@"face_btn_sel"]];
    professionalStars.tag = 1003;
	professionalStars.backgroundColor = [UIColor clearColor];
    professionalStars.rating = 0;
    zhuanye = 0;
    professionalStars.delegate = self;
	professionalStars.autoresizingMask =  UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    
    
    [zhuanyeView addSubview:professionalStars];
    
    
    
    professialLabel = [[UILabel alloc] initWithFrame:CGRectMake(bigView.frame.size.width-90, shoushiStars.frame.origin.y, 80, 30)];
    professialLabel.backgroundColor = [UIColor clearColor];
    
    professialLabel.text = @"";
    
    professialLabel.font = [UIFont systemFontOfSize:15.0];
    
    professialLabel.textColor = RGBA(240, 145, 38, 1.0);
    
    professialLabel.textAlignment = NSTextAlignmentRight;
    
    [zhuanyeView addSubview:professialLabel];
    
    
}

-(NSString *)judgeStateByNum:(NSString *)num{
    if ([num intValue] == 5) {
        return @"很满意";
    }else if ([num intValue] == 4){
        return @"满意";
    }else if ([num intValue] == 3){
        return @"一般";
    }else if ([num intValue] == 2){
        return @"差";
    }else if ([num intValue] == 1){
        return @"很差";
    }
    
    return @"";
}

#pragma mark
#pragma mark 获取默认评论数据
-(void)getNomalConmmentDatas
{
    NSDictionary * parms = @{@"OrderID": self.orderId,
                             @"CustomerID":[[NSUserDefaults standardUserDefaults] valueForKey:kMY_USER_ID]};
    ASIHTTPRequest * request = [XDTools postRequestWithDict:parms API:API_getReview];
    __weak ASIHTTPRequest * mrequest = request;
    [request setCompletionBlock:^{
        [XDTools hideProgress:self.contentView];
        NSDictionary * tmpDict = [XDTools JSonFromString:[mrequest responseString]];
        if ([tmpDict[@"status"] intValue]==1){
            NSDictionary * dict = tmpDict[@"data"];
            
            ReviewID = dict[@"ReviewID"];
            tfView.text = dict[@"ReviewContent"];
            if (IS_NOT_EMPTY(dict[@"ReviewContent"])){
                placeholderLB.hidden = YES;
            }
            total = [dict[@"Rewavg"] floatValue];
            if (total==0){
                total =5;
            }
            
            if (ARRAY_IS_NOT_EMPTY(dict[@"reviewavg"])){
                
                zhuanye = [[[dict[@"reviewavg"] firstObject] valueForKey:@"Avg"] floatValue];    //专业
                fuwu = [[[dict[@"reviewavg"] objectAtIndex:1] valueForKey:@"Avg"] floatValue];   //沟通
                shoushi = [[[dict[@"reviewavg"] lastObject] valueForKey:@"Avg"] floatValue];    //守时
            }else{
            }
            
            if (ARRAY_IS_NOT_EMPTY(dict[@"PhotoID"])){
                int i =0;
                for (UIImageView * view in picView.subviews){
                    if ([view isKindOfClass:[UIImageView class]]){
                        [view sd_setImageWithURL:[NSURL URLWithString:[dict[@"PhotoID"] objectAtIndex:i]] placeholderImage:nil];
                        i++;
                        if (i==[dict[@"PhotoID"] count]){
                            break;
                        }
                    }
                    
                }
                
                for (int i = 0;i<[dict[@"PhotoID"] count];i++){
                    
                    NSString * s =[[[dict[@"PhotoID"] objectAtIndex:i] componentsSeparatedByString:@"pid="] lastObject];
                    if ([picId isEqualToString:@""]) {
                        
                        picId = [picId stringByAppendingString:s];
                        
                    }else{
                        picId = [picId stringByAppendingString:[NSString stringWithFormat:@",%@",s]];
                    }
                }
            }
            
            _customNumberOfStars.rating = total;
            
            totalLabel.text = [NSString stringWithFormat: @"%.0f分",total];
            shoushiStars.rating = shoushi;
            serveStars.rating = fuwu;
            professionalStars.rating = zhuanye;
            

          
        }else{
            if (IS_NOT_EMPTY(tmpDict[@"msg"])){
                [XDTools showTips:tmpDict[@"msg"] toView:self.view];
            }
        }
    }];
    [request setFailedBlock:^{
        [XDTools hideProgress:self.contentView];
        [XDTools showTips:networkovertime toView:self.view];
    }];
    [request startAsynchronous];
    [XDTools showProgress:self.contentView];
   
}

@end
